#include <bits/stdc++.h>
using namespace std;
int a[5001], sum[5001], f[5001][5001];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 1; i <= n; i++) {
    f[i][i] = a[i];
  }
  for (int L = 2; L <= n; L++) {
    for (int i = 1; i <= n + 1 - L; i++) {
      int j = i - 1 + L;
      // i...j    a[i] [i+1,j]   [i,j-1] ,a[j]
      int x = a[i] + sum[j] - sum[i] - f[i + 1][j];
      int y = sum[j - 1] - sum[i - 1] - f[i][j - 1] + a[j];
      f[i][j] = max(x, y);
    }
  }
  cout << f[1][n];
  return 0;
}